From 637851afeeb49c1d6709ae49add67f7a8c0da787 Mon Sep 17 00:00:00 2001 From: Tim Deegan Date: Mon, 22 Jan 2007 11:49:11 +0000 Subject: [PATCH] [PYGRUB] Add python module for POSIX ptsname(2) function. Signed-off-by: Tim Deegan --- tools/Makefile | 1 + tools/ptsname/Makefile | 22 +++++++++++++++++++++ tools/ptsname/ptsname.c | 44 +++++++++++++++++++++++++++++++++++++++++ tools/ptsname/setup.py | 11 +++++++++++ 4 files changed, 78 insertions(+) create mode 100644 tools/ptsname/Makefile create mode 100644 tools/ptsname/ptsname.c create mode 100644 tools/ptsname/setup.py diff --git a/tools/Makefile b/tools/Makefile index b4156fc904..77ec437689 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -26,6 +26,7 @@ SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH)) SUBDIRS-y += python SUBDIRS-y += pygrub +SUBDIRS-y += ptsname endif .PHONY: all diff --git a/tools/ptsname/Makefile b/tools/ptsname/Makefile new file mode 100644 index 0000000000..a1db24c4c5 --- /dev/null +++ b/tools/ptsname/Makefile @@ -0,0 +1,22 @@ + +XEN_ROOT = ../.. +include $(XEN_ROOT)/tools/Rules.mk + +.PHONY: all +all: build +.PHONY: build +build: + CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build + +.PHONY: install +ifndef XEN_PYTHON_NATIVE_INSTALL +install: all + CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix="" +else +install: all + CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" +endif + +.PHONY: clean +clean: + rm -rf build tmp *.pyc *.pyo *.o *.a *~ a.out diff --git a/tools/ptsname/ptsname.c b/tools/ptsname/ptsname.c new file mode 100644 index 0000000000..3849bb8867 --- /dev/null +++ b/tools/ptsname/ptsname.c @@ -0,0 +1,44 @@ +/****************************************************************************** + * ptsname.c + * + * A python extension to expose the POSIX ptsname() function. + * + * Copyright (C) 2007 XenSource Ltd + */ + +#include +#include + +/* Needed for Python versions earlier than 2.3. */ +#ifndef PyMODINIT_FUNC +#define PyMODINIT_FUNC DL_EXPORT(void) +#endif + +static PyObject *do_ptsname(PyObject *self, PyObject *args) +{ + int fd; + char *path; + + if (!PyArg_ParseTuple(args, "i", &fd)) + return NULL; + + path = ptsname(fd); + + if (!path) + { + PyErr_SetFromErrno(PyExc_IOError); + return NULL; + } + + return PyString_FromString(path); +} + +static PyMethodDef ptsname_methods[] = { + { "ptsname", do_ptsname, METH_VARARGS }, + { NULL } +}; + +PyMODINIT_FUNC initptsname(void) +{ + Py_InitModule("ptsname", ptsname_methods); +} diff --git a/tools/ptsname/setup.py b/tools/ptsname/setup.py new file mode 100644 index 0000000000..5fbdfecd5c --- /dev/null +++ b/tools/ptsname/setup.py @@ -0,0 +1,11 @@ +from distutils.core import setup, Extension + +extra_compile_args = [ "-fno-strict-aliasing", "-Werror" ] + +setup(name = 'ptsname', + version = '1.0', + description = 'POSIX ptsname() function', + author = 'Tim Deegan', + author_email = 'Tim.Deegan@xensource.com', + license = 'GPL', + ext_modules = [ Extension("ptsname", [ "ptsname.c" ]) ]) -- 2.30.2